//
//  ViewController.m
//  JcApp
//
//  Created by 陈旺军 on 2021/6/1.
//

#import "ViewController.h"


// start============
@interface TestView:UIView

@end
@implementation TestView
-(instancetype) init{  //?
    self =  [super init];
    if (self) {
        
    }
    return self;
}

- (void)willMoveToSuperview:(nullable UIView *)newSuperview{
    [super willMoveToSuperview:newSuperview];
}
- (void)didMoveToSuperview{
    [super didMoveToSuperview];
}
- (void)willMoveToWindow:(nullable UIWindow *)newWindow{
    [super willMoveToWindow:newWindow];
}
- (void)didMoveToWindow{
    [super didMoveToWindow];
}

@end

// end ==========

@interface ViewController ()<UITextFieldDelegate> // 接口，对外开放
@property (nonatomic, copy) NSString *string; // 属性

@end

@implementation ViewController  // 实现

-(instancetype) init{
    self =  [super init];
    if (self) {
       
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.string = @"000";
//    [self.view addSubview:({
//        UILabel *label = [[UILabel alloc]init];
//        label.text = [self sdddd:@"123A" bbb:@"123B"];
//        [label sizeToFit];
//        label.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
//        label;
//    })];
//
//    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
//    [self.view addSubview:button];
//
//    button.frame = CGRectMake(0, 100, 50, 50);
//    button.backgroundColor = UIColor.redColor;
//    [button addTarget:self action:@selector(aaa) forControlEvents:(UIControlEventTouchUpInside)];
//
//
//    [self sdddd:@"AAA" bbb:@"BBB"];
//
//    BOOL B = NO;
//    if (B) {
//        NSLog(@"yes");
//    } else {
//        NSLog(@"NO");
//    }
    
    TestView *view =[[TestView alloc] init];// 申请空间，初始化
    view.backgroundColor =[UIColor redColor];
    view.frame = CGRectMake(100, 200, 100, 100);// 在父view的位置
    [self.view addSubview:view];
    

    // UILable
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20,  20, 100,  100)];
    label.text = @"hello world";
    label.backgroundColor = [UIColor blueColor];
    label.numberOfLines = 1;
//    label.lineBreakMode =[NS_ENUM:NSLineBreakByWordWrapping];
    [self.view addSubview:label];
    
    // UIButton
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];  // 控件风格
    [btn setBackgroundImage:[UIImage imageNamed:@"ic_01"] forState:UIControlStateNormal];
    btn.frame = CGRectMake(150, 50, 100, 100);
    [btn setTitle:@"点我一下" forState: UIControlStateNormal];
    [btn addTarget:self action:@selector(changeColor) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(80, 0, 0, 0)];
    [self.view addSubview:btn];
    
    // UITextFledld
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(20, 250, 200, 50)];
    textField.delegate = self;
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.placeholder=@"请输入文字";
    [self.view addSubview:textField];
    
    
    
}
// UITextFledId
-(BOOL) textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(nonnull NSString *)string{
    if (string.length>0) {
        if ([string characterAtIndex:0]<'0' || [string characterAtIndex:0]>'9') {
            NSLog(@"请输入数字");
            return NO;
        }
        if (textField.text.length+string.length>11) {
            NSLog(@"超过11位数");
            return NO;
        }
    }
    return YES;
}

// UIButton
- (void) changeColor{
    self.view.backgroundColor =[UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:arc4random()%255/255.0];
}


- (void)aaa {
    
    NSLog(@"12312312312312313x");
}

- (NSString *)sdddd:(NSString *)a
                bbb:(NSString *)b {
    NSLog(@"%@",a);
    
    return b;
}


@end
